$(document).ready(function(){
    $(".xuanzhepage").change(function () {
        // 获取将要查询的页数
        var pageSize = $(".xuanzhepage").val();
        $("#fpageSize").val(pageSize)
        $("#goFind").submit();
    });

});

function find() {
    $("#goFind").submit()
}

function tests() {
    window.location.href="/dictionary/testt";
}

/**
 * 翻页
 * @param pageNum
 */
function pageTurning(pageNum) {
    var pageSize = $(".xuanzhepage").val();
    $("#fpageSize").val(pageSize);
    $("#fpageNum").val(pageNum);
    $("#goFind").submit();
}

/**
 * 详情
 */
function details(id) {
    if(id!= null && id != ""){
        window.location.href = "/dictionary/details?id="+id;
    }else{
        alert("请选择要查看的用户");
    }
}

function save() {
    window.location.href = "/dictionary/saveAndEdit";
}

function edit(id) {
    if(id!= null && id!= ""){
        window.location.href = "/dictionary/saveAndEdit?id="+id;
    }else{
        alert("请选择要查看的用户");
    }
}

/**
 * 删除
 * @param id
 */
function deleteById(id) {
    if (confirm('确定要删除吗？')) {
        $.ajax({
            url: "/dictionary/deleteById/"+id,
            type: "DELETE",
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    alert(data.msg);
                    window.location.reload();
                } else {
                    alert("删除失败");
                }
            }
        });
    }
}


/**
 * 批量删除
 */
function deleteBatch() {
    var data = $("input[type='checkbox'][name='dictionaryCheck']:checked");
    if (data.length == 0) {
        alert("请选择您要删除的数据。")
        return;
    }
    var ids = [];

    data.each(function (){
        ids.push($(this).val())
    });

    if (ids.length == 0){
        alert('未获取到要删除的数据。')
        return;
    }

    if (confirm('确定要删除吗？')) {
        $.ajax({
            url: "/dictionary/deleteBatch",
            type: 'POST',
            data: {
                "ids": ids
            },
            dataType: "JSON",
            traditional:true,
            async: false,
            success: function (res) {
                if(res.code == "200") {
                    alert(res.msg);
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            }
        });
    }

}
